//
//  TableViewCellstyle2.m
//  BAOASystem
//
//  Created by michael on 2018/1/17.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "TableViewCellstyle2.h"
#import "CollectionViewCellsecfirst.h"
@implementation TableViewCellstyle2
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {

 _label = [[UILabel alloc]init];
    _label.frame = CGRectZero;
        _label.numberOfLines = 0;
      [_label setFont:[UIFont systemFontOfSize:14]];
       [self.contentView addSubview:_label];
    _view = [[UIView alloc]init];
    _view.frame = CGRectZero;
       [self.contentView addSubview:_view];
    
           _view2 = [[UIView alloc]init];
    _view2.frame = CGRectZero;
       [self.contentView addSubview:_view2];
       
        self.collectionView.frame = CGRectMake(0, 40, KScreenWidth,(KScreenWidth-30)/4);

 [self.contentView addSubview:self.collectionView];
    
       _image = [[UIImageView alloc]init];
    _image.frame = CGRectZero;
       [self.contentView addSubview:_image];
    
    

}

return self;

}
-(UICollectionView *)collectionView{
if (!_collectionView) {
  UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((KScreenWidth-30)/4,(KScreenWidth-30)/4);

    layout.minimumLineSpacing = 10;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40, KScreenWidth,(KScreenWidth-30)/4) collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
//    _collectionView.pagingEnabled = true;
//    _collectionView.scrollEnabled=NO;
    _collectionView.backgroundColor = [UIColor clearColor];
        [_collectionView registerNib:[UINib nibWithNibName:@"CollectionViewCellsecfirst" bundle:nil] forCellWithReuseIdentifier:@"XLCycleCell1"];
//self.collectionView.alwaysBounceVertical = YES;

    _collectionView.showsHorizontalScrollIndicator = false;
    
}
return _collectionView;
}
-(void)setArray:(NSArray *)array{
[self.collectionView reloadData]; //重新换数据源的时候 记得重回用的cell上的
_array = array;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return self.array.count;

}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString* cellId = @"XLCycleCell1";
    CollectionViewCellsecfirst *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
    cell.dic = _array[indexPath.row];
        [cell layoutSubviews];

    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *dic = _array[indexPath.row];
NSLog(@"111");
NSString *pdid =dic[@"id"];
shangpinxqViewController *vc = [[shangpinxqViewController alloc]init];
vc.pdid = pdid;
vc.hidesBottomBarWhenPushed = YES;
[self.ViewController.navigationController pushViewController:vc animated:YES];
}

- (void)layoutSubviews{
[super layoutSubviews];
  _view.frame = CGRectMake(5, 10, 10, 20);
    _view.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

NSString *string =NSLocalizedString(@"主推商品", nil);
CGFloat width = [UILabel getWidthWithTitle:string font:_label.font ];
 _label.frame = CGRectMake(_view.right+10,10, width+10, 20);
    _label.text  = NSLocalizedString(@"主推商品", nil);
    _label.textColor = [UIColor colorWithHexString:@"0a62ea"];
   _label.font = [UIFont boldSystemFontOfSize:14];
  _image.frame = CGRectMake(_label.right+10, 10, 50, 20);
//   _image.image = [UIImage imageNamed:NSLocalizedString(@"每日更新", nil)];
//   _image.image = [UIImage imageNamed:@"每日更新"];

        self.collectionView.frame = CGRectMake(0, 40, KScreenWidth,(KScreenWidth-30)/4);
//[self.collectionView reloadData];
_view2.frame = CGRectMake(0, _collectionView.bottom, KScreenWidth, 10);
    _view2.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];

}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
